package org.rency.common.trigger.beans;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 任务状态枚举
 * @author: user_rcy@163.com
 * </br>Created on 2015年11月12日
 * @version: V1.0.0
 * @since JDK 1.8
 */
public enum TaskStatusEnum {
    NORMAL("NORMAL","正常"),
    PROCESS("PROCESS","执行中"),
    PAUSE("PAUSE","暂停"),
    EXCEPTION("EXCEPTION","异常"),
    ;

    /** 代码 */
    private final String code;
    /** 信息 */
    private final String msg;

    /**
     * 构造
     * @param code
     * @param message
     */
    TaskStatusEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 根据代码获取
     * @param code
     * @return
     */
    public static TaskStatusEnum get(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }

        for (TaskStatusEnum type : TaskStatusEnum.values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }

        return null;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public String toString(){
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
}
